package com.undefined.socket.client;

import com.undefined.bean.User;

import java.io.*;
import java.net.Socket;

public class SocketClient {
    public static void main(String args[]) throws Exception {
        // 要连接的服务端IP地址和端口
        String host = "127.0.0.1";
        int port = 55533;
        // 与服务端建立连接
        Socket socket = new Socket(host, port);
        // 建立连接后获得输出流
        OutputStream outputStream = socket.getOutputStream();
        String message = "你好  yiwangzhibujian";
        User user = new User();
        user.setAge(31);
        user.setUserName("鼠海波");


//        ByteArrayOutputStream bos = new ByteArrayOutputStream();
//        ObjectOutputStream oos = new ObjectOutputStream(bos);
//        oos.writeObject(user);

        new ObjectOutputStream(socket.getOutputStream()).writeObject(user);

       // socket.getOutputStream().write(bos.toByteArray());
        outputStream.close();
        socket.close();
    }
}
